package com.xqgl.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xqgl.bean.Village;
import com.xqgl.service.VillageDaoImp;

/**
 * Servlet implementation class addVillageServlet
 */
@WebServlet("/addVillageServlet")
public class addVillageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addVillageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;Charset=utf-8");
		String num = request.getParameter("villagenum");
		String name = request.getParameter("villagename");
		String dz = request.getParameter("villageaddress");
		Double size = Double.parseDouble(request.getParameter("villagesize"));
		int zls = Integer.parseInt(request.getParameter("villagefloor"));
		int zhs = Integer.parseInt(request.getParameter("villagehousehold"));
		int lhl = Integer.parseInt(request.getParameter("villagegreen"));
		String kfs = request.getParameter("developername");
		String wy = request.getParameter("propertyname");
		String ctime = request.getParameter("villagectime");
		String zt = request.getParameter("villagestate");
		Village village = new Village();
		village.setVillagenum(num);
		village.setVillagename(name);
		village.setVillageaddress(dz);
		village.setVillagesize(size);
		village.setVillagefloor(zls);
		village.setVillagehousehold(zhs);
		village.setVillagegreen(lhl);
		village.setDevelopername(kfs);
		village.setPropertyname(wy);
		village.setVillagectime(ctime);
		village.setVillagestate(zt);
		VillageDaoImp imp = new VillageDaoImp();
		try {
			imp.add(village);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.sendRedirect("communitylist.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
